package com.object;
import java.util.ArrayList;
import java.util.Scanner;
public class Pet {
    private  String id ;
    private String name;
    private String gender;
    private String age;
    private String kind;
    private String color;
    private int price;

    public Pet(String id, String name, String gender, String age, String kind, String color, int price) {
        this.id = id;
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.kind = kind;
        this.color = color;
        this.price = price;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public Pet(){}

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public ArrayList<Pet> initPet(ArrayList<Pet>pets){
        Pet pet1 = new Pet("9653","来福","公","1年半","田园犬","褐白色",300);
        Pet pet2 = new Pet("4568","常威","公","6个月","田园犬","纯黑色",350);
        Pet pet3 = new Pet("9456","坤坤","公","2年半","小坤坤","黑白色",2500);
        Pet pet4 = new Pet("7885","鲁班","母","5个月","小柯基","黄白色",2000);
        Pet pet5 = new Pet("3596","笑笑","母","7个月","小柴犬","黑黄色",3000);
        pets.add(pet1);
        pets.add(pet2);
        pets.add(pet3);
        pets.add(pet4);
        pets.add(pet5);
        return pets;
    }
    public void showPet(ArrayList<Pet>pets,ArrayList<OperateLog>operateLogs,User user){
        System.out.println("ID    昵称    性别    年龄    品种    颜色    价格");
        String type = "查看宠物";
        new OperateLog().addLog(operateLogs, user, type);
        for (Pet pet : pets) {
            System.out.println(pet.getId()+"  "+pet.getName()+"    "+pet.getGender()+"    "+pet.getAge()+"     "+pet.getKind()+"  "+pet.getColor()+"    "+pet.getPrice());
        }
    }
    //判断宠物在不在购物车内
    public boolean inCar(User user,String id){
        for (ShoppingCart shoppingCart : user.getShoppingCarts()) {
            if(id.equals(shoppingCart.getId())){
                System.out.println(shoppingCart.getName()+"已在购物车内");
                return true;
            }
        }
        return  false;
    }
    public void buyPet(ArrayList<Pet>pets, ArrayList<OperateLog>operateLogs, User user, Scanner scanner){
        System.out.println("请输入您要购买的宠物id --->输入1取消");
        String petId = scanner.next();
            if (petId.equals("1")){
            return;
        }
        if(inCar(user,petId)){
            buyPet(pets,operateLogs,user,scanner);
        }
        boolean isFind = false;
        Pet pet = new Pet();
        for (Pet pet1 : pets) {
            if(pet1.getId().equals(petId)){
                pet = pet1;
                isFind = true;
                break;
            }
        }
        if(!isFind){
            System.out.println("您输入的id不存在");
            buyPet(pets,operateLogs,user,scanner);
        }else {
            if(!inCar(user,petId)){
                System.out.println("是否确定要购买"+pet.getName()+"? 1:确定 其他:取消");
                String choose = scanner.next();
                if(choose.equals("1")){
                    ShoppingCart shoppingCart = new ShoppingCart();
                    shoppingCart.addInShopping(user,operateLogs,pet,scanner);
                    String type = "查看宠物"+pet.getName();
                    operateLogs = new OperateLog().addLog(operateLogs, user, type);
                    System.out.println("是否继续购买  1:继续购买   2:不买了");
                }else {
                    System.out.println("用户取消了购买");
                    String type = "取消购买"+pet.getName();
                    new OperateLog().addLog(operateLogs, user, type);
                    System.out.println("是否继续购买？1:继续 其他:返回");
                }
                String id1 = scanner.next();
                if(id1.equals("1")){
                    buyPet(pets,operateLogs,user,scanner);
                }
            }
        }
    }
    public ArrayList<Pet> removePet(User user,ArrayList<Pet>pets){
        for (Order order : user.getOrders()) {
            if(order.getState().equals("已支付")){
                for (OrderList orderList : order.getOrderLists()) {
                    for (Pet pet : pets) {
                        if(orderList.getId().equals(pet.getId())){
                            pets.remove(pet);
                            break;
                        }
                    }
                }
            }
        }

        return pets;
    }
}
